<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateOrderItemsTable extends Migration {
    public function up() {
        Schema::create('order_items', function (Blueprint $table) {
            $table->id();
            //所属订单 ID
            $table->unsignedBigInteger('order_id');
            $table->foreign('order_id')->references('id')->on('orders')->onDelete('cascade');
            //对应商品 ID
            $table->unsignedBigInteger('product_id');
            $table->foreign('product_id')->references('id')->on('products')->onDelete('cascade');
            //对应商品 SKU ID
            $table->unsignedBigInteger('product_sku_id');
            $table->foreign('product_sku_id')->references('id')->on('product_skus')->onDelete('cascade');
            //数量
            $table->unsignedInteger('amount');
            //单价
            $table->decimal('price', 10, 2);
            //用户打分
            $table->unsignedInteger('rating')->nullable();
            //用户评价
            $table->text('review')->nullable();
            //评价时间
            $table->timestamp('reviewed_at')->nullable();
        });
    }

        /**
         * Reverse the migrations.
         *
         * @return void
         */
        public
        function down() {
            Schema::dropIfExists('order_items');
        }
    }
